package com.htht.smartschool.action.login;

import java.util.Map;

import com.htht.smartschool.action.baseaction.BaseAction;
import com.htht.smartschool.common.model.ParamData;
import com.htht.smartschool.common.servlet.DataContainer;
import com.htht.smartschool.model.user.TUser;
import com.htht.smartschool.service.login.LoginService;
import com.htht.smartschool.util.system.GsonUtils;

public class LoginAction extends BaseAction{

	public boolean processData(DataContainer obj,ParamData pd) {
		LoginService loginService = new LoginService();
		boolean flag = false;
		TUser tuser = (TUser) GsonUtils.getInstance().fromJson(pd.getData(), TUser.class);
		if(pd.getCmd().equalsIgnoreCase("login")){
			@SuppressWarnings("rawtypes")
			Map map = loginService.login(tuser);
			if (map != null && map.get("userinfo") != null) {
				flag = true;
				obj.setData(map);
			} else if(map != null && map.get("info") != null) {
				obj.setData(false);
			} else {
				obj.setData("用户名或密码错误！");
			}
		}else if(pd.getCmd().equalsIgnoreCase("checkUser")){
			TUser user = loginService.checkUser(tuser);
			if (user != null) {
				flag = true;
				obj.setData(user);
			} else {
				obj.setData("userkey错误");
			}
		}
		return flag;
	}

}
